package com.bee.gateway.common.dto;

import com.alibaba.fastjson.JSON;
import com.bee.gateway.common.domain.FilterDefinition;
import com.bee.gateway.common.domain.PredicateDefinition;
import com.bee.gateway.common.domain.RoutesDO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 对应gateway的RouteDefinition
 * @author  Damin.yang
 * @date  2019/7/30 16:39
 */
@Data
@NoArgsConstructor
public class RouteDefinitionDTO {

    private Long id;
    private String uri;
    private Integer order;
    private List<FilterDefinition> filters;
    private List<PredicateDefinition> predicates;

    public RouteDefinitionDTO(RoutesDO routesDO) {
        this.id = routesDO.getId();
        this.uri = routesDO.getUri();
        this.order = routesDO.getOrders();
        this.filters = JSON.parseArray(routesDO.getFilters(), FilterDefinition.class);
        this.predicates = JSON.parseArray(routesDO.getPredicates(), PredicateDefinition.class);
    }
}
